package br.com.ffm.praticas.facade;

import java.sql.SQLException;
import java.util.List;

import br.com.ffm.praticas.bean.Country;
import br.com.ffm.praticas.dao.CountryDAO;



public class CountryFACADE {
	
	private static CountryFACADE countryFacade;
	private static CountryDAO countryDAO;
	
	private CountryFACADE(){
		countryDAO = new CountryDAO();
	}
	
	/**
	 * Method that return an unique instance of CountryFACADE
	 * @return An instance of CountryFACADE
	 */
	public static CountryFACADE getInstance(){
		if(countryFacade == null){
			countryFacade = new CountryFACADE();
		}
		return countryFacade;
	}
	
	/**
	 * Method that returns all the Countries
	 * @return List<Country>
	 * @throws SQLException
	 */
	public List<Country> getCountries() throws SQLException {
		return countryDAO.getCountries();
	}
	
	/**
	 * Method that search a Country by ID
	 * @param id The ID of the Country to be found
	 * @return If found returns it, else returns null
	 * @throws SQLException 
	 */
	public Country getCountry(int id) throws SQLException{
		return countryDAO.getCountry(id);
	}
	
	/**
	 * Method that search a Country by Description
	 * @param description The Description of the Country to be found
	 * @return If found returns it, else returns null
	 * @throws SQLException 
	 */
	public Country getCountry(String description) throws SQLException{
		return countryDAO.getCountry(description);
	}
	
	/**
	 * Method that count the number of countries
	 * @return
	 * @throws SQLException 
	 */
	public int count() throws SQLException{
		return countryDAO.getCountries().size();
	}

}
